package com.filter;

import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public abstract class AbstractFilterChain<R,T> {
    protected List<Filter<R,T>> filters = new ArrayList<Filter<R, T>>();
    public List<R> doFilter(List<T> list){
        //创建要返回的错误集合汇总
        List<R> rlist = new ArrayList<R>();
        for (Filter<R, T> filter: filters) {
            Collection<R> rs = filter.doFilter(list);
            if (CollectionUtils.isNotEmpty(rs)){
                rlist.addAll(rs);
            }
        }
        return rlist;
    }
}
